home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / AMScen_0_9.lha / AMScen / quests.m < prev    next >
Text File  |  1995-01-21  |  17KB  |  630 lines

  1. /*
  2.  * Amiga MUD
  3.  *
  4.  * Copyright (c) 1995 by Chris Gray
  5.  */
  6.  
  7. /*
  8.  * quests.m - define the quest setup for the starter scenario.
  9.  */
  10.  
  11. private tp_quests CreateTable().
  12. use tp_quests
  13.  
  14. /* define some Quest stuff here so that we can refer to it from everywhere */
  15.  
  16. define t_quests QuestThing CreateThing(nil).
  17. define t_quests p_QuestState CreateIntProp().
  18. define t_quests p_QuestActive CreateActionProp().
  19. define t_quests p_pQuestDoneList CreateThingListProp().
  20. define tp_quests p_sQuestName CreateStringProp().
  21. define tp_quests p_sQuestDesc CreateActionProp().
  22. define tp_quests p_sQuestChecker CreateActionProp().
  23. define tp_quests p_sQuestHint CreateActionProp().
  24. define tp_quests p_sQuestType CreateIntProp().
  25. define tp_quests QUEST_DIRECT    0.
  26. define tp_quests QUEST_GIVE    1.
  27. define tp_quests QUEST_TELL    2.
  28. define tp_quests p_sQuestList CreateThingListProp().
  29.  
  30. define tp_quests proc dummy()void: corp;
  31. QuestThing@p_QuestState := 0.
  32. QuestThing@p_QuestActive := dummy.
  33. QuestThing@p_sQuestList := CreateThingList().
  34.  
  35. define t_quests proc QuestDirect(string name; action desc, checker, hint)void:
  36.     thing quest;
  37.  
  38.     if desc = nil or checker = nil or hint = nil then
  39.     Print("*** Invalid action given to QuestDirect.\n");
  40.     else
  41.     quest := CreateThing(nil);
  42.     quest@p_sQuestName := name;
  43.     quest@p_sQuestDesc := desc;
  44.     quest@p_sQuestChecker := checker;
  45.     quest@p_sQuestHint := hint;
  46.     quest@p_sQuestType := QUEST_DIRECT;
  47.     AddTail(QuestThing@p_sQuestList, quest);
  48.     fi;
  49. corp;
  50.  
  51. define t_quests proc QuestGive(string name; action desc, checker, hint)void:
  52.     thing quest;
  53.  
  54.     if desc = nil or checker = nil or hint = nil then
  55.     Print("*** Invalid action given to QuestGive.\n");
  56.     else
  57.     quest := CreateThing(nil);
  58.     quest@p_sQuestName := name;
  59.     quest@p_sQuestDesc := desc;
  60.     quest@p_sQuestChecker := checker;
  61.     quest@p_sQuestHint := hint;
  62.     quest@p_sQuestType := QUEST_GIVE;
  63.     AddTail(QuestThing@p_sQuestList, quest);
  64.     fi;
  65. corp;
  66.  
  67. define t_quests proc public GiveToQuestor(string what)void:
  68.     thing me;
  69.  
  70.     me := TrueMe();
  71.     SPrint(me, "You give the " + what + " to Questor.\n");
  72.     ABPrint(AgentLocation(me), me, nil,
  73.         FormatName(me@p_pName) + AAn(" gives", what) + " to Questor.\n");
  74. corp;
  75.  
  76. define t_quests proc QuestTell(string name; action desc, checker, hint)void:
  77.     thing quest;
  78.  
  79.     if desc = nil or checker = nil or hint = nil then
  80.     Print("*** Invalid action given to QuestTell.\n");
  81.     else
  82.     quest := CreateThing(nil);
  83.     quest@p_sQuestName := name;
  84.     quest@p_sQuestDesc := desc;
  85.     quest@p_sQuestChecker := checker;
  86.     quest@p_sQuestHint := hint;
  87.     quest@p_sQuestType := QUEST_TELL;
  88.     AddTail(QuestThing@p_sQuestList, quest);
  89.     fi;
  90. corp;
  91.  
  92. define t_quests proc public DoQuest(action checker)void:
  93.     list thing quests, lt;
  94.     thing me, quest;
  95.     int i;
  96.  
  97.     me := Me();
  98.     quests := QuestThing@p_sQuestList;
  99.     for i from 0 upto Count(quests) - 1 do
  100.     quest := quests[i];
  101.     if quest@p_sQuestChecker = checker then
  102.         lt := me@p_pQuestDoneList;
  103.         if lt = nil then
  104.         lt := CreateThingList();
  105.         me@p_pQuestDoneList := lt;
  106.         fi;
  107.         if FindElement(lt, quest) ~= -1 then
  108.         Print("You have already completed the " +
  109.             quest@p_sQuestName + " quest!\n");
  110.         else
  111.         AddTail(lt, quest);
  112.         APrint("\n" + FormatName(me@p_pName) +
  113.             " has completed a quest!!\n\n");
  114.         fi;
  115.     fi;
  116.     od;
  117. corp;
  118.  
  119. define t_quests proc public DoneQuest(action checker)bool:
  120.     list thing lt;
  121.     int i;
  122.     bool found;
  123.  
  124.     found := false;
  125.     lt := Me()@p_pQuestDoneList;
  126.     if lt ~= nil then
  127.     for i from 0 upto Count(lt) - 1 do
  128.         if lt[i]@p_sQuestChecker = checker then
  129.         found := true;
  130.         fi;
  131.     od;
  132.     fi;
  133.     found
  134. corp;
  135.  
  136. define t_util proc ShowQuests(thing who)bool:
  137.     list thing lt;
  138.     int count;
  139.  
  140.     lt := who@p_pQuestDoneList;
  141.     if lt = nil then
  142.     false
  143.     else
  144.     count := Count(lt);
  145.     if count = 0 then
  146.         false
  147.     else
  148.         Print(who@p_pName + " has completed ");
  149.         if count = 1 then
  150.         Print("one quest.\n");
  151.         else
  152.         IPrint(count);
  153.         Print(" quests.\n");
  154.         fi;
  155.         true
  156.     fi
  157.     fi
  158. corp;
  159.  
  160. define tp_quests Questor CreateThing(nil).
  161. define tp_quests p_rQuestUser CreateThingProp().
  162. define tp_quests p_pSaveIdle CreateActionProp().
  163.  
  164. define tp_quests QUESTROOM_ID NextEffectId().
  165. define tp_quests proc drawQuestRoom()void:
  166.     int i;
  167.  
  168.     if not KnowsEffect(nil, QUESTROOM_ID) then
  169.     DefineEffect(nil, QUESTROOM_ID);
  170.     GSetImage(nil, "questRoom");
  171.     IfFound(nil);
  172.         GShowImage(nil, "", 0, 0, 160, 100, 0, 0);
  173.     Else(nil);
  174.         for i from 0 upto 3 do
  175.         GSetPen(nil, i + 1);
  176.         GAMove(nil, 16 + i, 24 + i);
  177.         GRectangle(nil, 128 - 2 * i, 52 - 2 * i, false);
  178.         od;
  179.         GSetPen(nil, C_GOLD);
  180.         GAMove(nil, 28, 48);
  181.         GText(nil, "Complete your");
  182.         GAMove(nil, 36, 56);
  183.         GText(nil, "quests here");
  184.     Fi(nil);
  185.     EndEffect();
  186.     fi;
  187.     CallEffect(nil, QUESTROOM_ID);
  188. corp;
  189.  
  190. define tp_quests r_questRoom CreateThing(nil).
  191. SetupRoom(r_questRoom, "in Questor's office",
  192.     "The office is old-fashioned, but quite opulent in its way. The walls "
  193.     "are lined with shelves and racks containing all sorts of trophies. "
  194.     "There are fine collections of Bushman spears, Watusi shields, "
  195.     "Aborigine horns, Iroquois pipes, samurai swords, Malay masks, "
  196.     "modern skateboards, Meershaum pipes, etc. One large case contains "
  197.     "a zoo of live-looking animals, many of which you cannot classify. "
  198.     "A shelf contains jars, each filled with smaller, very dead-looking "
  199.     "animals. Many appear to have faces and hands. Questor's desk is a "
  200.     "large construction of red-swirled marble. It is quite neat and tidy, "
  201.     "with a couple of piles of papers, a fine onyx pen-stand and a trio "
  202.     "of Faberge eggs. Behind the desk is a matching marble chair with "
  203.     "purple velvet cushions and a pair of huge gems as handrests. Arching "
  204.     "over Questor's head (for he is sitting in the chair watching you as "
  205.     "you stare around) is a cobra with flaring hood, carved from pure "
  206.     "white marble. The cobra's eyes are deep red and it seems to be watching "
  207.     "you.").
  208. r_questRoom@p_rNoMachines := true.
  209. Scenery(r_questRoom,
  210.     "wall,shelf,shelves,rack,trophy,trophies,collection,case;fine,large."
  211.     "spear;Bushman."
  212.     "shield;Watusi."
  213.     "horn;Aborigine."
  214.     "pipe;Iroquois."
  215.     "sword;samurai."
  216.     "mask;Malay."
  217.     "skateboard,board;skate,modern."
  218.     "pipe;Meerschaum."
  219.     "zoo."
  220.     "animal;live-looking,live,looking,dead-looking,dead."
  221.     "jar."
  222.     "face,hand."
  223.     "desk;large,red-swirled,red,swirled,marble."
  224.     "paper,pile;piles,of."
  225.     "pen-stand,stand;pen,fine,onyx."
  226.     "egg;Faberge,trio,of."
  227.     "chair;matching,marble."
  228.     "cushion;purple,velvet."
  229.     "gem,handrest,rest;hand,pair,of,huge,gem."
  230.     "cobra,hood;with,flaring,hood,pure,white,marble."
  231.     "eye;cobra's,cobra,deep,red."
  232.     "beard,mustache,eyebrow,brow;eye,long,flowing,massive,white."
  233.     "cloak,satin;long,flowing,jet-black,jet,black,satin."
  234.     "pendant;extremely,large,ugly."
  235.     "q,'q';letter."
  236.     "chain,link;chain,of,iron.").
  237. RoomGraphics(r_questRoom, "Questor's", "Office", NextMapGroup(), 0, 0,
  238.          drawQuestRoom).
  239. FakeObject(CreateThing(nil), r_questRoom, "eye;Questor's,Questor",
  240.     "Questor's eyes are not something you want to stare at.").
  241. FakeObject(CreateThing(nil), r_questRoom, "eye;cobra's,snake's,cobra,snake",
  242.     "The stone cobra's eyes seem to be watching you.").
  243.  
  244. /*
  245.  * Just in case some wise-guy wizard tries to force him out.
  246.  */
  247.  
  248. define tp_quests proc questorExit()status:
  249.  
  250.     if Me() = Questor then
  251.     fail
  252.     else
  253.     continue
  254.     fi
  255. corp;
  256. AddAnyLeaveChecker(r_questRoom, questorExit, false).
  257.  
  258. define tp_quests proc emptyQuestor()void:
  259.     list thing lt;
  260.     int i;
  261.     thing th;
  262.  
  263.     lt := Questor@p_pCarrying;
  264.     i := Count(lt);
  265.     while i ~= 0 do
  266.     i := i - 1;
  267.     th := lt[i];
  268.     ZapObject(th);
  269.     DelElement(lt, th);
  270.     od;
  271. corp;
  272.  
  273. define tp_quests proc questIdle()void:
  274.     action a;
  275.  
  276.     emptyQuestor();
  277.     a := Me()@p_pSaveIdle;
  278.     ignore SetCharacterIdleAction(a);
  279.     Me() -- p_pSaveIdle;
  280.     SetLocation(r_questRoom@p_rExit);
  281.     Questor -- p_rQuestUser;
  282.     if a ~= nil then
  283.     call(a, void)();
  284.     fi;
  285. corp;
  286.  
  287. define tp_quests proc questEnter()status:
  288.     thing who;
  289.     action a;
  290.  
  291.     who := Questor@p_rQuestUser;
  292.     if who = nil then
  293.     if Me()@p_pName ~= "Packrat" then
  294.         Questor@p_rQuestUser := Me();
  295.         Print(
  296.         "The huge door opens easily, and you enter Questor's office.\n"
  297.         "NOTE: no-one else can enter the office while you are in it - "
  298.         "please keep your stay as short as possible. Thank-you.\n");
  299.         a := SetCharacterIdleAction(questIdle);
  300.         if a ~= nil then
  301.         Me()@p_pSaveIdle := a;
  302.         fi;
  303.     fi;
  304.     continue
  305.     else
  306.     Print("The huge door will not open - you cannot enter. Questor is "
  307.         "currently in conference with " + FormatName(who@p_pName) + ".\n");
  308.     fail
  309.     fi
  310. corp;
  311.  
  312. define tp_quests proc questExit()status:
  313.     action a;
  314.  
  315.     emptyQuestor();
  316.     Questor -- p_rQuestUser;
  317.     ignore SetCharacterIdleAction(Me()@p_pSaveIdle);
  318.     Me() -- p_pSaveIdle;
  319.     Print("You open the huge door and go outside. "
  320.     "Questor can now deal with other players.\n");
  321.     QuestThing@p_QuestState := 0;
  322.     continue
  323. corp;
  324.  
  325. define tp_quests proc showQuests()string:
  326.     list thing lt;
  327.     int count, i, oldIndent;
  328.     thing quest;
  329.     string result;
  330.  
  331.     lt := QuestThing@p_sQuestList;
  332.     count := Count(lt);
  333.     if count = 0 then
  334.     result := "There are no quests yet.";
  335.     else
  336.     result := "The current quests are:";
  337.     oldIndent := GetIndent();
  338.     for i from 0 upto count - 1 do
  339.         quest := lt[i];
  340.         result := result + "\n  " + quest@p_sQuestName + " quest: " +
  341.         call(quest@p_sQuestDesc, string)();
  342.     od;
  343.     result := result + "\nIf you need a hint on a quest, just ask.";
  344.     fi;
  345.     result
  346. corp;
  347.  
  348. define tp_quests proc questHint(string what)bool:
  349.     list thing lt;
  350.     thing quest;
  351.     int count, i;
  352.     bool found;
  353.  
  354.     if what = "" then
  355.     Print("Use 'hint <quest-name>' to get a hint for a given quest.\n");
  356.     false
  357.     else
  358.     lt := QuestThing@p_sQuestList;
  359.     count := Count(lt);
  360.     if count = 0 then
  361.         Print("There are no quests yet!\n");
  362.         false
  363.     else
  364.         if SubString(what, 0, 6) = "quest;" then
  365.         what := SubString(what, 6, Length(what) - 6);
  366.         fi;
  367.         found := false;
  368.         for i from 0 upto count - 1 do
  369.         quest := lt[i];
  370.         if quest@p_sQuestName == what then
  371.             Print(call(quest@p_sQuestHint, string)() + "\n");
  372.             found := true;
  373.         fi;
  374.         od;
  375.         if not found then
  376.         Print("There is no '" + what + "' quest.\n");
  377.         false
  378.         else
  379.         true
  380.         fi
  381.     fi
  382.     fi
  383. corp;
  384.  
  385. define tp_quests proc questorStep()void:
  386. corp;
  387.  
  388. define tp_quests proc questorSay(string what)void:
  389.     list thing lt;
  390.     thing quest, player;
  391.     int count, i;
  392.     bool found, foundSpecial;
  393.     string who, word, specialWord;
  394.  
  395.     player := Questor@p_rQuestUser;
  396.     SetIt(player);
  397.     who := SetSay(what);
  398.     found := false;
  399.     specialWord := "";
  400.     while
  401.     word := GetWord();
  402.     word ~= "" and not found
  403.     do
  404.     lt := QuestThing@p_sQuestList;
  405.     count := Count(lt);
  406.     i := 0;
  407.     while i ~= count and not found do
  408.         quest := lt[i];
  409.         if quest@p_sQuestType = QUEST_TELL and
  410.         call(quest@p_sQuestChecker, bool)(word)
  411.         then
  412.         found := true;
  413.         i := count;
  414.         lt := player@p_pQuestDoneList;
  415.         if lt = nil then
  416.             lt := CreateThingList();
  417.             player@p_pQuestDoneList := lt;
  418.         fi;
  419.         if FindElement(lt, quest) ~= -1 then
  420.             SPrint(player, "You have already completed the " +
  421.             quest@p_sQuestName + " quest!\n");
  422.         else
  423.             SPrint(player,
  424.             "Questor smiles warmly and says: Congratulations " +
  425.             who +  ", you have completed the " +
  426.             quest@p_sQuestName + " quest!\n");
  427.             AddTail(lt, quest);
  428.             APrint("\n" + who + " has completed a quest!!\n\n");
  429.         fi;
  430.         else
  431.         if word == "quest" or word == "quests" or
  432.             word == "info" or word == "information" or
  433.             word == "help" or word == "hint" or word == "hints"
  434.         then
  435.             specialWord := word;
  436.         fi;
  437.         i := i + 1;
  438.         fi;
  439.     od;
  440.     od;
  441.     if not found then
  442.     if specialWord ~= "" then
  443.         if specialWord == "hint" or specialWord == "hints" then
  444.         DoSay("Go outside and ask - don't bother me!");
  445.         else
  446.         DoSay("To find out about quests, read the sign outside!");
  447.         fi;
  448.     elif who ~= "Packrat" then
  449.         DoSay("Quit gabbing and get down to it!");
  450.     fi;
  451.     fi;
  452. corp;
  453.  
  454. define tp_quests proc questorWhisperMe(string what)void:
  455.  
  456.     if SetWhisperMe(what) ~= "" then
  457.     DoSay("Don't try to get familiar with me!");
  458.     fi;
  459. corp;
  460.  
  461. define tp_quests proc questorOverhear(string what)void:
  462.  
  463.     DoSay("Whispering is impolite!");
  464. corp;
  465.  
  466. define tp_quests proc questorSaw(string what)void:
  467.  
  468.     DoSay("Stop messing around!");
  469. corp;
  470.  
  471. define tp_quests proc questorNoNo()status:
  472.  
  473.     Print("Questor glares at you, and so does the cobra!\n");
  474.     fail
  475. corp;
  476.  
  477. define tp_quests proc questorCreate()void:
  478.  
  479.     Questor@p_pStandard := true;
  480.     SetupMachine(Questor);
  481.     Questor@p_pDesc :=
  482.     "Questor is a tall, skinny man with a long, flowing white beard and "
  483.     "an equally long and flowing mustache. His massive white eyebrows "
  484.     "don't flow quite as much. He wears a long, flowing (naturally) cloak "
  485.     "of jet-black satin with no decorations. His head is bare (and a "
  486.     "little bit bald on top), but on his chest is an extremely large "
  487.     "and ugly pendant in the shape of the letter 'Q'. It is supported on "
  488.     "a massive chain of iron links. Wearing this may account for his "
  489.     "perpetual look of annoyance. All of these things you notice only "
  490.     "briefly, before you look at his eyes, which are bright grey, and "
  491.     "seem to penetrate to your very core.";
  492.     CreateMachine("Questor", Questor, r_questRoom, questorStep);
  493.     ignore SetMachineActive(Questor, questorStep);
  494.     ignore SetMachineSay(Questor, questorSay);
  495.     ignore SetMachineWhisperMe(Questor, questorWhisperMe);
  496.     ignore SetMachineWhisperOther(Questor, questorOverhear);
  497.     ignore SetMachinePose(Questor, questorSaw);
  498.     GNewIcon(Questor, makeQuestorIcon());
  499.     Questor@p_oTouchChecker := questorNoNo;
  500.     Questor@p_oSmellChecker := questorNoNo;
  501.     Questor@p_oPushChecker := questorNoNo;
  502.     Questor@p_oPullChecker := questorNoNo;
  503.     Questor@p_oTurnChecker := questorNoNo;
  504.     Questor@p_oLiftChecker := questorNoNo;
  505.     Questor@p_oLowerChecker := questorNoNo;
  506.     Questor@p_oEatChecker := questorNoNo;
  507. corp;
  508. questorCreate();
  509. ignore DeleteSymbol(tp_quests, "questorCreate").
  510.  
  511. define tp_quests proc questorPre()status:
  512.     list thing lt;
  513.     thing me, item, quest;
  514.     string name;
  515.     int count, i;
  516.     status st;
  517.     bool found;
  518.  
  519.     me := TrueMe();
  520.     item := It();
  521.     name := FormatName(me@p_pName);
  522.     lt := QuestThing@p_sQuestList;
  523.     count := Count(lt);
  524.     found := false;
  525.     i := 0;
  526.     while i ~= count do
  527.     quest := lt[i];
  528.     if quest@p_sQuestType = QUEST_GIVE then
  529.         st := call(quest@p_sQuestChecker, status)();
  530.         if st ~= continue then
  531.         found := true;
  532.         i := count;
  533.         lt := me@p_pQuestDoneList;
  534.         if lt = nil then
  535.             lt := CreateThingList();
  536.             me@p_pQuestDoneList := lt;
  537.         fi;
  538.         if st = succeed then
  539.             if FindElement(lt, quest) ~= -1 then
  540.             SPrint(me,
  541.                    "Questor frowns and says: " + name +
  542.                    ", you have already completed the " +
  543.                    quest@p_sQuestName + " quest!\n");
  544.             else
  545.             SPrint(me,
  546.                 "Questor smiles warmly and says: Congratulations "+
  547.                   name +  ", you have completed the " +
  548.                   quest@p_sQuestName + " quest!\n");
  549.             AddTail(lt, quest);
  550.             APrint("\n" + name + " has completed a quest!!\n\n");
  551.             fi;
  552.         fi;
  553.         ZapObject(item);
  554.         DelElement(me@p_pCarrying, item);
  555.         else
  556.         i := i + 1;
  557.         fi;
  558.     else
  559.         i := i + 1;
  560.     fi;
  561.     od;
  562.     if found then succeed else continue fi
  563. corp;
  564.  
  565. Questor@p_pGivePre := questorPre.
  566.  
  567. define tp_quests questSign CreateThing(nil).
  568.  
  569. /*
  570.  * SetupQuestorOffice - set things up so that the given direction from the
  571.  *    given location leads to Questor's office.
  572.  */
  573.  
  574. define t_quests proc SetupQuestorOffice(thing where; int dir)void:
  575.  
  576.     Connect(where, r_questRoom, dir);
  577.     Connect(where, r_questRoom, D_ENTER);
  578.     AddDirChecker(where, dir, questEnter, false);
  579.     AddDirChecker(r_questRoom, DirBack(dir), questExit, false);
  580.     AddEnterChecker(where, questEnter, false);
  581.     AddExitChecker(r_questRoom, questExit, false);
  582.     ExtendDesc(where,
  583.     "The building here appears to be constructed from solid granite "
  584.     "blocks and is quite featureless. The door is a large one of foot-"
  585.     "thick oak beams strengthed with iron straps. There are no windows. "
  586.     "In the center of the door is the letter 'Q', pounded out of thick "
  587.     "iron. Beside the door, a discreet sign labelled \"Quests\" has a "
  588.     "list of some kind.");
  589.     Scenery(where,
  590.     "block;solid,granite."
  591.     "building;featureless."
  592.     "door,beam;foot-thick,foot,thick,oak."
  593.     "strap;iron."
  594.     "q,'q',letter;letter,thick,pounded,iron");
  595.     FakeObject(questSign, where,
  596.     "sign;discreet.sign,list,quest;discreet,quest,quests", "");
  597.     questSign@p_oReadAction := showQuests;
  598.     where@p_rHintAction := questHint;
  599. corp;
  600.  
  601. /* setup the 'quests' verb */
  602.  
  603. define tp_quests proc v_quests()bool:
  604.     string name;
  605.     thing who;
  606.  
  607.     name := GetWord();
  608.     if name = "" then
  609.     if not ShowQuests(Me()) then
  610.         Print("You have not yet completed any quests.\n");
  611.     fi;
  612.     true
  613.     else
  614.     who := FindAgent(name);
  615.     if who ~= nil then
  616.         if not ShowQuests(who) then
  617.         Print(name + " has not yet completed any quests.\n");
  618.         fi;
  619.         true
  620.     else
  621.         Print("There is no " + name + " here.\n");
  622.         false
  623.     fi
  624.     fi
  625. corp;
  626.  
  627. VerbTail(G, "quests", v_quests).
  628.  
  629. unuse tp_quests
  630.